/**
 * Copyright [2010] Delta Air Lines, Inc. All Rights Reserved Access,
 * Modification, or Use Prohibited Without Express Permission of Delta Air
 * Lines.
 */
package com.delta.rafg.core.database;


import java.util.ArrayList;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;

import com.delta.rafg.core.config.ConfigSettings;


/**
 * DataHandlerOptions.this class holds database property and ConfigSettings.
 * @author Delta
 * @version 1.0
 * @see ConfigSettings
 */
public class DataHandlerOptions {

    /**
     * Holds the values of available override options.
     */
	public static enum OVERIDE_OPTION {
	   IGNORE_JNDI
    }

    /**
     * Holds the value of overideOptions.
     */
    private List<OVERIDE_OPTION> overideOptions = null;

    /**
     * Holds the value of strDriverClassName property.
     */
    private String strDriverClassName = null;

    /**
     * Holds the value of strConnectionUrl property.
     */
    private String strConnectionUrl = null;

    /**
     * Holds the value of strProtocol property.
     */
    private String strProtocol = null;

    /**
     * Holds the value of strJndiName property.
     */
    private String strJndiName = null;

    /**
     * Holds the value of strUsername property.
     */
    private String strUsername = null;

    /**
     * Holds the value of strPassword property.
     */
    private String strPassword = null;

    /**
     * Holds the value of strServiceName property.
     */
    private String strServiceName = null;
    /**
     * Holds the value of dataHandlerPropertyIdentifier property.
     */
    private String dataHandlerPropertyIdentifier = null;

    /**
     * Holds the value of configSettings property.
     */
    private ConfigSettings configSettings = null;

    /**
     *
     */
    private Map<String, Object> dataHandlerSpecificOptionsMap;

    /**
     * @return the configSettings
     */
    public ConfigSettings getConfigSettings() {

        return configSettings;
    }

    /**
     * @return strConnectionUrl;
     */
    public final String getConnectionUrl() {

        return strConnectionUrl;
    }

    /**
     * @return strProtocol
     */
    public final String getProtocol() {

        return strProtocol;
    }

    /**
     * @return the dataSourcePropertyIdentifier
     */
    public String getDataHandlerPropertyIdentifier() {

        return dataHandlerPropertyIdentifier;
    }

    /**
     * Any configuration options unique to a specific datahandler are defined in
     * this map. The act of calling this method will create and return an empty
     * map.
     * @return the dataHandlerSpecificOptionsMap
     */
    public final Map<String, Object> getDataHandlerSpecificOptionsMap() {

        if (dataHandlerSpecificOptionsMap == null) {
            dataHandlerSpecificOptionsMap = new Hashtable<String, Object>();
        }
        return dataHandlerSpecificOptionsMap;
    }

    /**
     * @return the driverClassName
     */
    public final String getDriverClassName() {

        return strDriverClassName;
    }

    /**
     * @return returns the JNDI Name for the Connection Pool.
     */
    public final String getJndiName() {

        return strJndiName;
    }

    /**
     * @return password for datasource
     */
    public final String getPassword() {

        return strPassword;
    }

    /**
     * @return username for datasource
     */
    public final String getUsername() {

        return strUsername;
    }

    /**
     * Check if a DataHandlerSpecificOptionsMap object has been specified.
     * @return true if a DataHandlerSpecificOptionsMap has been created within
     *         this DataHandlerOptions object.
     */
    public final boolean hasDataHandlerSpecificOptionsMap() {

        boolean flag = true;
        if (dataHandlerSpecificOptionsMap == null) {
            flag = false;
        }
        return flag;
    }

    /**
     * @param configSettings the configSettings to set
     */
    public void setConfigSettings(final ConfigSettings configSettings) {

        this.configSettings = configSettings;
    }

    /**
     * @param connectionUrl - Url string of database connection
     */
    public final void setConnectionUrl(final String connectionUrl) {

        strConnectionUrl = connectionUrl;
    }

    public final void setProtocol(final String protocol) {

        strProtocol = protocol;
    }

    /**
     * @param dataSourcePropertyIdentifier the dataSourcePropertyIdentifier to
     *            use
     */
    public void setDataHandlerPropertyIdentifier(
        final String dataHandlerPropertyIdentifier) {

        this.dataHandlerPropertyIdentifier = dataHandlerPropertyIdentifier;
    }

    /**
     * @param driverClassName the driverClassName to set
     */
    public final void setDriverClassName(final String driverClassName) {

        strDriverClassName = driverClassName;
    }

    /**
     * @param jndiName - JNDI Name to use for Connection Pool. set null if JNDI
     *            is not being used for this data connection.
     */
    public final void setJndiName(final String jndiName) {

        strJndiName = jndiName;
    }

    /**
     * @param password password for datasource
     */
    public final void setPassword(final String password) {

        strPassword = password;
    }

    /**
	 * @param serviceName the strServiceName to set.
	 */
	public void setServiceName(String serviceName) {
		this.strServiceName = serviceName;
	}

	/**
	 * @return the ServiceName
	 */
	public String getServiceName() {
		return strServiceName;
	}

	/**
     * @param username - username for datasource
     */
    public final void setUsername(final String username) {

        strUsername = username;
    }

    /**
     * @param opt
     */
    public void addOverideOption(OVERIDE_OPTION opt) {
        if (overideOptions == null) {
            overideOptions = new ArrayList<OVERIDE_OPTION>(1);
        }
        if (!overideOptions.contains(opt)) {
            overideOptions.add(opt);
        }
    }

    /**
     * @param opt
     */
    public void removeOverideOption(OVERIDE_OPTION opt) {
        if (overideOptions != null && overideOptions.contains(opt)) {
            overideOptions.remove(opt);
        }
    }

    /**
     * @param opt
     * @return
     */
    public boolean hasOverideOption(OVERIDE_OPTION opt) {
        if (overideOptions != null && overideOptions.contains(opt)) {
            return true;
        } else {
            return false;
        }
    }
}
